package com.dongnao.jack.spring.parse;

import java.io.Serializable;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.dongnao.jack.registry.handler.RegistryDelegate;

/**
 * 
 * @ClassName: ServiceConfig 
 * @Description: 服务端springbean的配置
 * @author xuyp
 * @date 2018年4月17日 下午2:11:41 
 *
 */
public class ServiceConfig implements Serializable, InitializingBean, ApplicationContextAware {

    public static ApplicationContext applicationContext;

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = 7759990481724111717L;

    /**
     * 接口类全路径
     */
    private String interfaceClass;

    /**
     * 服务端id
     */
    private String ref;

    /**
     * 调用服务使用的协议
     */
    private String protocol;

    public String getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(String interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    public String getRef() {
        return ref;
    }

    public void setRef(String ref) {
        this.ref = ref;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    @Override
    public String toString() {
        return "ServiceConfig [interfaceClass=" + interfaceClass + ", ref=" + ref + ", protocol=" + protocol + "]";
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    public void afterPropertiesSet() throws Exception {

        RegistryDelegate.registryService(this);

    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

}
